package com.xn.app.muying.activity;

import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.util.APIMethod;
import com.xn.app.muying.util.BaseActivity;
import com.xn.app.muying.util.MyAlertDialog;
import com.xn.app.muying.util.NetworkUtil;
import com.xn.app.muying.util.ToastUtil;
import com.zhuge.analysis.stat.ZhugeSDK;

/**
 * 医生详情信息
 * Created by Administrator on 2016/11/9.
 */
public class DoctorInfoActivity extends BaseActivity {

    //加载框
    private AlertDialog dialog;
    private WebView webview = null;
    //返回键
    private ImageView img_back=null;
    //标题
    private TextView title_name=null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doctorinfo);
        String id = getIntent().getStringExtra("id");
        img_back = (ImageView) findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        title_name = (TextView) findViewById(R.id.title_name);
        title_name.setText("医生详情");
        webview = (WebView) findViewById(R.id.activity_doctorinfo_webview);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub

                view.loadUrl(url);
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                return true;
            }

            //页面开始加载
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                dialog = new MyAlertDialog().ShowDialog(DoctorInfoActivity.this, R.layout.dialog_loading);
                dialog.setCancelable(true);
            }

            //加载结束 （其实页面404等等错误的情况也算加载完成）
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (dialog != null) {
                    dialog.dismiss();
                }
                webview.setVisibility(WebView.VISIBLE);
            }
        });
        //获取数据
        if (NetworkUtil.isNetworkAvailable(DoctorInfoActivity.this)) {
            webview.loadUrl(APIMethod.DoctorInfo(id));
        } else {
            ToastUtil.showToast(DoctorInfoActivity.this, R.string.no_network_hint);
        }

    }
    @Override
    protected void onResume() {
        super.onResume();
    }
}
